using UnityEngine;
using System.Collections;

public class StartGame : MonoBehaviour {

	private string ip = "localhost";
	private int porta = 25000;
	private bool gameStarted = false;

	
	public GameObject character;
	public Vector3 characterPosition;

	void Awake() {
		Application.runInBackground = true;
	}
	
	void Start () {
		
	}
	
	void OnGUI(){
		
		if(Network.peerType == NetworkPeerType.Disconnected){
			if (GUILayout.Button ("Connect")){
				Network.Connect(ip,porta);
			}
			if (GUILayout.Button ("Start Server")){
				Network.InitializeServer(25,porta, false);
			}
		}else{
			if(!gameStarted){
			//instancia um player na tela
			 	Network.Instantiate(character,characterPosition, character.gameObject.transform.rotation,0);
				
			//destroy objeto atual
				Destroy(this);
			}
			
			if (GUILayout.Button ("Disconnect")){
				Network.Disconnect(200);
			}
			gameStarted = true;
		}
	}
}
